/*
 * 
 *后台目标管理弹出框
 * */
var target_control=function(the_target_id,the_id,img,user_id,user_name){
	$('#'+the_id).append('<div class="dialog"></div><div class="my_dialog" style="top:10%"></div><div class="my_dialog" style="top:15%"></div>');
	$('#'+the_id+' div.my_dialog:eq(0)').append('<h4>目标详情</h4><i class="fa fa-times"></i><div class="target_dialog" style="padding: 0.5em 1em 2em 0.5em;;background:white"></div>');
	$('#'+the_id+' div.my_dialog:eq(1)').append( '<h4>目标分享</h4><i class="fa fa-times"></i><div style="padding:0.5em 1em;background:white">'+
             '<textarea  placeholder="#晒我的目标#每天完成一个小目标，虽然微小，但千里之行，始于足下，  终有一天我会实现我的大目标#智行校园之我的目标# https://mb.yunhua.com/ebill/index.htm"name="target_describe"></textarea>'+
             '<button class="target_share">分享到广场</button><img class="the_user" src="'+img+'"/><h4 >智行校园</h4><span >我的目标分享</span>'+
            ' <textarea  placeholder="#晒我的目标#每天完成一个小目标，虽然微小，但千里之行，始于足下，  终有一天我会实现我的大目标#智行校园之我的目标# https://mb.yunhua.com/ebill/index.htm" name="target_describe"></textarea>'+
            '<div class="share_dialog" style="background:#eeeeee;margin: 0 1.5em;padding-bottom:1em"><h3></h3><p></p>'+
            '<span id="toggle_article" >展开全文</span><h3 class="table-toggle">展开分解任务<i class="fa fa-caret-right fa-lg" ></i> </h3><div>'+
            '<table id="dialog_table_share"></table></div></div></div>');
	/*var detail_colums = [[ "target_id","target_describe", "target_sign","target_source","sign" ],
			              [ "序号", "描述", "签到次数", "相关资料" ,"今日签到"] ];*/
    var detail_share = [[ "target_id","target_describe","target_source", "target_sign" ],
		              [ "序号", "描述", "相关资料", "签到次数" ] ];
    var the_url='/College/jsp/occupation_evaluation/target_dialog.json';
	 $.ajax({
		 url:the_url,
		 data:{param1:the_target_id},
		 type:'post'
	 }).done(function(data){
		 var img='';
		 $('#'+the_id+'  div.my_dialog:eq(0) div.target_dialog').append('<h3>'+data.target+'</h3><button class="make_sure" style="margin-right:2.5em"> 删除</button><button><i class="fa fa-share-alt"></i>分享到广场</button>');
		 $('#'+the_id+'  div.my_dialog:eq(0) div.target_dialog').append('<p><font size="3" >描述：</font>'+data.describe+'</p><span id="toggle_article" >展开全文</span>');
		 if(data.sign_count!='0'){
		  for(var i=0;i<data.sign_img.length;i++)
			  img+='<img src="'+data.sign_img[i]+'"/>'
		  $('#'+the_id+'  div.my_dialog:eq(0) div.target_dialog').append('<p><font size="3" >今日签到：</font>'+img+'...共'+data.sign_count+'人</p>');
		 }
		 $('#'+the_id+'  div.my_dialog:eq(0) div.target_dialog').append('<font size="3" style="width:100%;margin-left:1.5em">目标分解：</font><div style="margin:0.2em 1.5em;width:calc(100% - 3em);"><table id="dialog_table"></table></div>');
		 $('div#table_dialog').show('slow');
		 var the_colum= detail_share;
					table("dialog_table",data.table,the_colum, false,150);
					$('div.my_dialog span#toggle_article').click(function(){
						$(this).text()=='展开全文'? $(this).text('收起').prev().css('height','auto')
								:$(this).text('展开全文').prev().css('height','2.4em');
					});
					$('button.make_sure').unbind('click').click(function(){
						win.confirm("系统提示","删除此目标会同时影响使用此目标的人，确定删除？");
						$('div.body-panel p.btns button:eq("0")').unbind('click').click(function(){
   	    				 win.close();
   	    				 $.ajax({
		    		    	   url:'',
		    		    	   data:{param1:user_id,param2:the_target_id},
		    		    	   type:'post',
		    		    	   success:function(){
		    		    		   win.alert("系统提示","目标已删除成功！");
		    		    		   $('div#'+the_id).hide('fast');
		    		    		  
		    		    		   $('#the_table').bootstrapTable('refresh',{
		    							url:'../../jsp/target/target_database.json? param2='+$('div.points_buttons button.selected').attr('value')+' &param1='+user_id
		    						});
		    		    	   }
		    		       });
						$('div#'+the_id).empty();
   	    			  });
	    		       
					});
					$('#'+the_id+' div.my_dialog:eq(0) button:contains(分享到广场)').click(function(){
						  $('#'+the_id+' div.my_dialog:eq(1) div.share_dialog h3:eq(0)').text(data.target);
						  $('#'+the_id+' div.my_dialog:eq(1) div.share_dialog p').html('<font size="3" >描述：</font>'+data.describe);
						  table("dialog_table_share",data.table,detail_share, false,250);
						  $('#'+the_id+' div.my_dialog:eq(1)').toggle();
						  $('#'+the_id+' div.my_dialog:eq(1) i.fa-caret-right').unbind('click').click(function(){
							  $('#'+the_id+' div.my_dialog:eq(1) h3.table-toggle').next().toggle();
						  });
						  $('#'+the_id+' div.my_dialog:eq(1) i.fa-times').unbind('click').click(function(e){
							  $('div#'+the_id+' div.my_dialog:eq(1)').hide('fast');
							  e.stopPropagation();
						  });
						  $('#'+the_id+' div.my_dialog:eq(1) button.target_share').unbind('click').click(function(e){
							  $.ajax({
			    		    	   url:'',
			    		    	   data:{param3:the_target_id,param1:user_id,param2:user_name,param4:$(this).prev().val()},
			    		    	   type:'post',
			    		    	   success:function(){
			    		    		   $('#'+the_id+' div.my_dialog:eq(1)').hide('fast');
			    		    		   win.alert("系统提示","分享成功！");
			    		    	   }
			    		       });
							  e.stopPropagation();
						  });
						  $('#'+the_id+' div.my_dialog:eq(1) textarea:eq(0)').bind('input propertychange', function() {
							  $('#'+the_id+' div.my_dialog:eq(1) textarea:eq(1)').text($(this).val());
						  });
					});
					$('div.my_dialog:eq(0) i.fa-times').click(function(){
						$('div#'+the_id).hide('fast');
						$('div#'+the_id).empty();
					});
					
	 });
};
function table(id, data,colums, pagination,height) {
	var colum = [];
	for (var i = 0; i < colums[0].length; i++)
    		   colum[i]={field:colums[0][i],title:colums[1][i],valign:"middle",align:"center"};
	$('#' + id).bootstrapTable({
		columns : colum,
		height:height,
		data : data,
		pagination : pagination,
		search : false,
		searchOnEnterKey : true,
		locale : 'zh-CN'
	});		
};

